﻿package 
{

	import flash.display.MovieClip;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.events.Event;
//ssss

	public class Main extends MovieClip
	{
		private var arr:Array = [];
		private var timer:Timer = new Timer(1000,61);
		private var timeText:TextField=new TextField();
		private var timeTextFormat:TextFormat=new TextFormat();
		private var tiao:Tiao;

		public function Main()
		{

			for (var i:int=0; i<10; i++)
			{
				var star:Star=new Star();
				star.x = Math.random() * 550;
				star.y = Math.random() * 400;
				arr.push(star);
				this.addChild(star);
			}
			this.addEventListener(Event.ENTER_FRAME,onFrame);

			timeTextFormat.size = 30;
			timeTextFormat.color = 0x0000ff;
			timeText.defaultTextFormat = timeTextFormat;
			timeText.text = '00' + timer.repeatCount + '';

			timer.addEventListener(TimerEvent.TIMER,onTimer);
			timer.start();
		}
		private function onFrame(e:Event):void
		{
			for (var i in arr)
			{
				arr[i].moves();
			}
		}
		private function onTimer(e:TimerEvent):void
		{
			timeText.text='00:'+(timer.repeatCount-timer.currentCount);
			timeText.x = 456;
			timeText.y = 368;
			this.addChild(timeText);
			if (timer.repeatCount - timer.currentCount == 55)
			{
				timeTextFormat.color = 0xff0000;
				timeText.defaultTextFormat = timeTextFormat;
				tiao=new Tiao();
				this.addChild(tiao);
			}
			else if (timer.repeatCount - timer.currentCount <= 50)
			{
				timer.stop();
				for(var i:int=0;i<numChildren+22;i++ )
				{
					removeChildAt(0)
				}
				var gameover:Gameover=new Gameover();
				this.addChild(gameover);
				trace(numChildren)
			}

		}
	}

}